<?php

class Jf_View_Helper_LoadBlock extends Jf_View_Helper_Abstract {

    public function loadBlock ($block, $arguments = array()) {
        if (stripos ($block, '/')) {
            $parts = explode ('/', $block);
            $module = ucfirst (array_shift ($parts));
            $block = '';
            foreach ($parts as $key => $value) {
                if ($key != 0) {
                    $block .= '_';
                }
                $block .= ucwords ($value);
            }
        } else {
            $dispatcher = Jf_Controller_Dispatcher::getInstance ();
            $module = $dispatcher -> getRequest () -> getModuleName ();
        }
        $blockClass = $module . '_Block_' . ucfirst ($block);
        if ( ! Jf_Registry::isRegistered ($blockClass)) {
            $instance = new $blockClass ($arguments);
            Jf_Registry::set ($blockClass, $instance);
        }
        return Jf_Registry::get ($blockClass);
    }

}
